<template>
	<view class="content">
		<view style="height: 225rpx;background-color: #1262DB;">
			<view style="height: 40rpx;"></view>
			<view class="wid90 mar bacFFF borRad10">
				<uni-datetime-picker v-model="datetimerange" type="daterange" rangeSeparator="至" @change="changeTime" />
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 " style="margin-top: -60rpx;">
			<view class="wid90 mar hei80 dis disAl disJuB">
				<view class="foSi35" style="border-left: 6rpx solid #1262DB;padding-left: 10rpx;">总检测数据：</view>
				<view class="dis disAl foSi20">
					<view>订单总数：<span style="color: #FF0000;">{{all_ordernum}}</span></view>
					<view class="mar-left20">项目总数：<span style="color: #FF0000;">{{all_orderproduct}}</span></view>
				</view>
			</view>
			<view class="mar-top20 foSi20 wid90 mar" style="border: 1rpx solid #2088f8;">
				<view class="hei80 dis disAl coFFF" style="background-color: #1262DB;">
					<view class="hei100 dis disAl disJuC" style="width: 35%;border-right: 1rpx solid #2088f8;">机构名称</view>
					<view class="hei100 dis disAl disJuC" style="width: 20%;border-right: 1rpx solid #2088f8;">订单数量</view>
					<view class="hei100 dis disAl disJuC" style="width: 20%;border-right: 1rpx solid #2088f8;">项目数量</view>
					<view class="hei100 dis disAl disJuC" style="width: 25%;">检测金额</view>
				</view>
				<view v-if="list.length != 0" style="border: 1rpx solid #2088f8;" class="dis" v-for="(item,index) in list" :key="index" @click="goclinic_detail(item.id)">
					<view class="dis disAl disJuC padd" style="width: 35%;border-right: 1rpx solid #2088f8;">{{item.name}}</view>
					<view class="dis disAl disJuC padd" style="width: 20%;border-right: 1rpx solid #2088f8;flex-direction: column;">{{item.ordernum}}</view>
					<view class="dis disAl disJuC padd" style="width: 20%;border-right: 1rpx solid #2088f8;flex-direction: column;">{{item.order_project}}</view>
					<view class="dis disAl disJuC padd" style="width: 25%;flex-direction: column;">￥{{item.all_price}}</view>
				</view>
				<view v-if="list.length == 0" class="dis disAl disJuC foSi30" style="color: #B8B7B7;height: 160rpx;">暂无更多数据</view>
			</view>
			<view style="height: 20rpx;"></view>
		</view>
		<view class="wid90 mar" v-if="system_type == 2">
			<view style="height: 1rpx;"></view>
			<view v-if="orderlist.length == 0" style="height: 600rpx;" class="wid100 dis disAl disJuC">
				<image src="../../static/incomeDetail/wushiju.png" style="width: 197rpx;height: 226rpx;"></image>
			</view>
			<view v-if="orderlist.length != 0" class="wid100 mar mar-top20 bacFFF borRad20 foSi30" v-for="(item,index) in orderlist" :key="index" @click="godetail(item.id)">
				<view style="height: 10rpx;"></view>
				<view class="hei80 wid90 mar dis disAl disJuB">
					<view style="font-weight: 600;">{{item.clinic_name}}</view>
					<view class="foSi25" style="color: #AEACAC;">订单状态：<span style="color: red;" v-if="item.status == 1">待支付</span><span style="color: orange;" v-if="item.status == 2">检测中</span><span style="color: green;" v-if="item.status == 3">已完成</span><span style="color: #616161;" v-if="item.status == 4">已取消</span></view>
				</view>
				<view class="hei60 dis disAl disJuB wid90 mar borRad10 foSi20" style="background-color: #E5E5E5;">
					<view style="width: 48%;">下单时间：{{item.createtime}}</view>
					<view style="width: 48%;">单号：{{item.order_id}}</view>
				</view>
				<view class="wid90 mar" v-for="(item1,index1) in item.dlist" :key="index1" style="display: flex;justify-content: space-between;align-items: center;">
					<view class="dis disAl" style="padding: 20rpx 0;">{{index1+1+'、'+item1.ssued}}</view>
					<view style="font-size: 14px;color:red" v-if="item1.status == 1">待支付</view>
					<view style="font-size: 14px;color: orange;" v-if="item1.status == 2">检测中</view>
					<view style="font-size: 14px;color: green;" v-if="item1.status == 3">{{item1.result_data}}</view>
					<view style="font-size: 14px;color: #616161;" v-if="item1.status == 4">已取消</view>
				</view>
				<view class="wid90 mar foSi25 mar-top20" style="color: #AEACAC;">
					<!-- <view>设备编号：{{item.device_no_number}}</view> -->
					<view class="mar-top10">支付时间：{{item.pay_time}}</view>
				</view>
				<view style="height: 20rpx;"></view>
			</view>
			<view style="height: 30rpx;"></view>
		</view>
		<view class="wid90 mar" v-if="system_type == 1">
			<view style="height: 1rpx;"></view>
			<view v-if="orderlist.length == 0" style="height: 600rpx;" class="wid100 dis disAl disJuC">
				<image src="../../static/incomeDetail/wushiju.png" style="width: 197rpx;height: 226rpx;"></image>
			</view>
			<view v-if="orderlist.length != 0" class="wid100 mar mar-top20 bacFFF borRad20 foSi30" v-for="(item,index) in orderlist" :key="index">
				<view style="height: 10rpx;"></view>
				
				<view class="hei80 wid90 mar dis disAl disJuB">
					<view style="font-weight: 600;">{{item.name}}</view>
					<!-- <view class="foSi25" style="color: #AEACAC;">订单状态：<span style="color: red;" v-if="item.status == 1">待支付</span><span style="color: orange;" v-if="item.status == 2">检测中</span><span style="color: green;" v-if="item.status == 3">已完成</span><span style="color: #616161;" v-if="item.status == 4">已取消</span></view> -->
				</view>
				<view class="hei60 dis disAl disJuB wid90 mar borRad10 foSi20" style="background-color: #E5E5E5;">
					<view style="width: 48%;">下单时间：{{item.createtime}}</view>
					<view style="width: 48%;">单号：{{item.order_id}}</view>
				</view>
			
				<view class="wid90 mar foSi25 mar-top20" style="color: #AEACAC;">
					<!-- <view>设备编号：{{item.device_no_number}}</view> -->
					<view class="mar-top10">支付时间：{{item.pay_time}}</view>
				</view>
				<view style="height: 20rpx;"></view>
			</view>
			<view style="height: 30rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				datetimerange:[],
				all_ordernum: '',
				all_orderproduct: '',
				orderlist: [],
				page:1,
				system_type:1
			}
		},
		onLoad() {
			this.system_type = uni.getStorageSync('system_type')
			this.dangqian()
		},
		onReachBottom () {
			this.page += 1
		      this.getOrderlist()
		    },
		methods: {
			goclinic_detail(id){
				uni.navigateTo({
					url:'/pages/myGroup/instdetails?id='+id
				})
			},
			godetail(id){
				uni.navigateTo({
					url:'/pages/checkorder/orderdetail?id='+id
				})
			},
			changeTime(e) {
				this.datetimerange = e;
				if(e.length != 0){
					this.getuserinfo()
					this.page = 1
					this.orderlist = []
					this.getOrderlist()
				}
			},
			dangqian(){
				this.zhanshi = 0
				var date = new Date()
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				var day = date.getDate()
				this.datetimerange = [year+'-'+month+'-'+day,year+'-'+month+'-'+day]
				this.getuserinfo()
				this.getOrderlist()
			},
			getuserinfo(){
				var that = this
				console.log('身份'+uni.getStorageSync('system_type'))
				if(uni.getStorageSync('system_type') == 1){
					var urls = 'api/order/index'
				}else{
					var urls = 'api/order/index2'
				}
				uni.request({
				    url: that.global.url + urls,
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						begintime: this.datetimerange[0],
						endtime: this.datetimerange[1],
					},
				    success(res) {
				        let result = res.data
				        if(result.code == 1){
							that.list = result.data.data
							that.all_ordernum = result.data.all_ordernum
							that.all_orderproduct = result.data.all_orderproduct
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    }
				})
			},
			getOrderlist(){
				var that = this
				uni.showLoading({
					title:'加载中'
				})
				if(uni.getStorageSync('system_type') == 1){
					var urls = 'api/order/orderlist'
				}else{
					var urls = 'api/order/orderlist2'
				}
				uni.request({
				    url: that.global.url + urls,
				    method: "POST",
					header: {
						'token': uni.getStorageSync('token')
					},
				    data: {
						begintime: this.datetimerange[0],
						endtime: this.datetimerange[1],
						type: 1,
						page:that.page
					},
				    success(res) {
				        let result = res.data
						console.log(result.data)
				        if(result.code == 1){
							if(that.system_type == 1){
								that.orderlist = that.orderlist.concat(result.data)
							}else{
								that.orderlist = that.orderlist.concat(result.data.data)
							}
							
						}else{
				           uni.showToast({
				           	title: result.msg,
				           	icon: 'error'
				           })
				        }
				       
				    },complete() {
				    	uni.hideLoading()
				    }
				})
			},
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F0F1F4;
	}
	.uni-date-x--border {
		height: 90rpx;
	}
	.padd{
		padding: 26rpx 2%;box-sizing: border-box;
	}
</style>
